package org.idea.qiyu.framework.rpc.dubbo.router.starter.local.provider;


import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.idea.qiyu.framework.rpc.dubbo.router.starter.local.service.ITestService;
import org.idea.qiyu.framework.rpc.dubbo.router.starter.local.service.TestServiceImpl;

/**
 * @Author linhao
 * @Date created in 8:27 下午 2021/7/28
 */
public class TestProvider {

    public static final String ZK_ADDR = "127.0.0.1:2181";

    public static void main(String[] args) throws InterruptedException {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("test-local-application-demo");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(ZK_ADDR);
        registryConfig.setProtocol("zoneAware");
        applicationConfig.setRegistry(registryConfig);

        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(9093);
        protocol.setThreads(200);

        ServiceConfig<ITestService> serviceServiceConfig = new ServiceConfig<>();
        serviceServiceConfig.setApplication(applicationConfig);
        serviceServiceConfig.setProtocol(protocol);
        serviceServiceConfig.setFilter("providerContextFilter");
        serviceServiceConfig.setInterface(ITestService.class);
        serviceServiceConfig.setRef(new TestServiceImpl());
        serviceServiceConfig.export();
        System.out.println("服务注册并且暴露成功！！");
        while (true) {
            Thread.sleep(1000);
        }
    }
}